
'use strict';
goog.provide('Blockly.Python.Inout');

goog.require('Blockly.Python');



Blockly.Python.inout_highlow = function() {
  var dropdown_d_value = this.getFieldValue('text_values');
  // TODO: Assemble JavaScript into code variable.
  var code = dropdown_d_value;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Python.ORDER_ATOMIC];
};




Blockly.Python.inout_digital_pin = function() {
  var dropdown_d_value = this.getFieldValue('d_pin_values');
  // TODO: Assemble JavaScript into code variable.
  var code = dropdown_d_value;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Python.ORDER_ATOMIC];
};


Blockly.Python.inout_analog_pin = function() {
  var dropdown_d_value = this.getFieldValue('a_pin_values');
  // TODO: Assemble JavaScript into code variable.
  var code = dropdown_d_value;
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Python.ORDER_ATOMIC];
};

Blockly.Python['inout_digital_write'] = function() {
  var value_pin = Blockly.Python.valueToCode(this, 'pin', Blockly.Python.ORDER_ATOMIC);
  var value_p_value = Blockly.Python.valueToCode(this, 'p_value', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var p_value=0;
  if(value_p_value=='HIGH'){
    p_value=1;
  }

  Blockly.Python.definitions_['setup_output_' + value_pin]='await self.set_pin_mode([' + value_pin + ', 1])';
  var code = 'await self.digital_write([' + value_pin + ', ' + p_value + '])\n';
  return code;
};


Blockly.Python['inout_digital_read'] = function() {
  var value_pin = Blockly.Python.valueToCode(this, 'pin', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Python.definitions_['setup_output_' + value_pin]='await self.set_pin_mode([' + value_pin + ', 0])';
  var code = 'await self.get_tmp_digital_value('+value_pin+')';
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Python.ORDER_STRING_CONVERSION];
};

Blockly.Python['inout_analog_write'] = function() {
  var value_pin = Blockly.Python.valueToCode(this, 'pin', Blockly.Python.ORDER_ATOMIC);
  var value_p_value = Blockly.Python.valueToCode(this, 'p_value', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Python.definitions_['setup_output_' + value_pin]='await self.set_pin_mode(["' + value_pin+ '", 1])';
  var code = 'await self.analog_write(["' + value_pin + '", ' + value_p_value + '])\n';
  return code;
};


Blockly.Python['inout_analog_read'] = function() {
  var value_pin = Blockly.Python.valueToCode(this, 'pin', Blockly.Python.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  Blockly.Python.definitions_['setup_output_' + value_pin]='await self.set_pin_mode(["' + value_pin+ '", 2])';
  var code = 'await self.get_tmp_analog_value("'+value_pin+'")';
  // TODO: Change ORDER_NONE to the correct strength.
  return [code, Blockly.Python.ORDER_STRING_CONVERSION];
};
